From 3389ddf6fc8ce84daa3b652bbbae749fbf02faa1 Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Tue, 26 Mar 2019 17:13:18 +0000 Subject: [PATCH] Do not connect to a non-existing signal The GtkWidget::parent-set signal was removed in ff6cd8f7. Instead of removing GtkLayoutChild instances associated to a widget using notifications when the widget's parent changes, we can have gtk_widget_unparent() call a method on GtkLayoutManager to remove any eventual GtkLayoutChild instances associated to the widget. --- gtk/gtklayoutmanager.c | 20 ++++++++++++-------- gtk/gtklayoutmanagerprivate.h | 3 +++ gtk/gtkwidget.c | 3 +++ 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/gtk/gtklayoutmanager.c b/gtk/gtklayoutmanager.c index 5047a58b20..3f05158262 100644 --- a/gtk/gtklayoutmanager.c +++ b/gtk/gtklayoutmanager.c @@ -283,12 +283,19 @@ gtk_layout_manager_layout_changed (GtkLayoutManager *manager) gtk_widget_queue_resize (priv->widget); } -static void -remove_layout_child (GtkWidget *widget, - GtkWidget *old_parent, - GtkLayoutManager *self) +/*< private > + * gtk_layout_manager_remove_layout_child: + * @manager: a #GtkLayoutManager + * @widget: a #GtkWidget + * + * Removes the #GtkLayoutChild associated with @widget from the + * given #GtkLayoutManager, if any is set. + */ +void +gtk_layout_manager_remove_layout_child (GtkLayoutManager *manager, + GtkWidget *widget) { - GtkLayoutManagerPrivate *priv = gtk_layout_manager_get_instance_private (self); + GtkLayoutManagerPrivate *priv = gtk_layout_manager_get_instance_private (manager); if (priv->layout_children != NULL) { @@ -296,8 +303,6 @@ remove_layout_child (GtkWidget *widget, if (g_hash_table_size (priv->layout_children) == 0) g_clear_pointer (&priv->layout_children, g_hash_table_unref); } - - g_signal_handlers_disconnect_by_func (widget, remove_layout_child, self); } /** @@ -372,7 +377,6 @@ gtk_layout_manager_get_layout_child (GtkLayoutManager *manager, g_assert (g_type_is_a (G_OBJECT_TYPE (res), GTK_TYPE_LAYOUT_CHILD)); g_hash_table_insert (priv->layout_children, child, res); - g_signal_connect (child, "parent-set", G_CALLBACK (remove_layout_child), manager); return res; } diff --git a/gtk/gtklayoutmanagerprivate.h b/gtk/gtklayoutmanagerprivate.h index d02ed56a6f..14eb30e161 100644 --- a/gtk/gtklayoutmanagerprivate.h +++ b/gtk/gtklayoutmanagerprivate.h @@ -7,4 +7,7 @@ G_BEGIN_DECLS void gtk_layout_manager_set_widget (GtkLayoutManager *manager, GtkWidget *widget); +void gtk_layout_manager_remove_layout_child (GtkLayoutManager *manager, + GtkWidget *widget); + G_END_DECLS diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c index 9d0dccc665..85c1bd06e5 100644 --- a/gtk/gtkwidget.c +++ b/gtk/gtkwidget.c @@ -3209,6 +3209,9 @@ gtk_widget_unparent (GtkWidget *widget) if (old_parent->priv->children_observer) gtk_list_list_model_item_removed (old_parent->priv->children_observer, old_prev_sibling); + if (old_parent->priv->layout_manager) + gtk_layout_manager_remove_layout_child (old_parent->priv->layout_manager, widget); + /* Now that the parent pointer is nullified and the unroot vfunc already * called, go ahead and unset the parent window, if we are unparenting * an embedded GtkWindow the window will become toplevel again and root -- 2.30.2